home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / 4dtnt.zip / WHERE.BTM < prev   
Text File  |  1991-11-03  |  2KB  |  88 lines

  1. rem Determine "WHERE" a particular command comes from -- internal, 
  2. rem alias, external, executable extension, etc.
  3.  
  4. rem None of the rems is necessary to proper operation and may be
  5. rem deleted for ordinary use.
  6.  
  7. setlocal
  8.  
  9. rem See if a command to check was supplied.
  10.  
  11. iff "%1" == "" then ^ echo Syntax: where command ^ quit
  12.  else
  13.  rem
  14.  rem separate the name and the extension (if any) 
  15.  rem
  16.  set targ=%@upper[%@name[%1]]
  17.  set ex=%@upper[%@ext[%1]]
  18. endiff
  19.  
  20. rem Skip some stuff if no extension
  21.  
  22. if "%ex" == "" goto noext
  23.  
  24. rem See if the extension is one of the usual executables
  25.  
  26. if %ex == COM .or. %ex == EXE .or. %ex == BTM .or. %ex == BAT goto catext
  27.  
  28. rem There is an extension, but it's not a normal executable.  See if there's
  29. rem such an extension in the environment -- i.e., a user-defined executable
  30. rem extension.
  31.  
  32. set ey=.%ex
  33. iff "%[%ey]" ne "" then
  34.  
  35.    rem It's a defined executable extension.  Tell the user.
  36.  
  37.    echo Executable extension = %@upper[%[%ey]]
  38.  
  39.    rem Now find out whether the program which is supposed to be run 
  40.    rem against the executable extension file is there!
  41.  
  42.    iff "%@path[%[%ey]]" == "" then
  43.      where %@name[%[%ey]].%@ext[%[%ey]]
  44.    endiff
  45.    iff not exist %[%ey] then 
  46.      echo Extension program not found
  47.    endiff
  48.  else
  49.    echo Executable extension .%ex definition not found
  50. endiff
  51.  goto cleanup
  52.  
  53. rem Above was for executable extensions.  What follows is the branch
  54. rem label for normal executables (.BTM, .BAT, .COM, and .EXE)
  55.  
  56. :catext
  57.  
  58. rem Put the file name back together with its extension.
  59.  
  60. set targ=%targ.%ex
  61. :noext
  62.  
  63. rem Check for alias or internal first, because they would be found first.
  64.  
  65. iff isalias %targ then
  66.   echo Alias
  67.   goto cleanup
  68.  elseiff isinternal %targ then
  69.   echo Internal
  70.   goto cleanup
  71. endiff
  72.  
  73. rem It wasn't an alias or an internal, look down the PATH
  74.  
  75. set targ=%@search[%targ]
  76. iff "%targ" ne "" then
  77.  echo %targ
  78. else
  79.  echo Unknown command
  80. endiff
  81. goto cleanup
  82. :cleanup
  83. endlocal
  84.  
  85. rem The branches to "cleanup" and the "endlocal" are not strictly necesary.
  86. rem They could all have been "quit", but I like programs to have a single
  87. rem exit point and exit in a way which is obviously clean.
  88.